package com.example.warehouse.config;


import com.example.warehouse.filter.LoginChechFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
public class ServletConfig {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        //创建fb对象
        FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean();
        //创建自定义的过滤器对
        LoginChechFilter loginChechFilter=new LoginChechFilter();
        //注入redis模板
        loginChechFilter.setRedisTemplate(redisTemplate);
        //讲自定义的过滤器注册到bean
        filterRegistrationBean.setFilter(loginChechFilter);
        //过滤拦截请求
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }
}
